import { TextUtils } from '../utils/TextUtils';
/**
 * 请求响应
 */

export class BaseResponse<T> {
  msg: string;
  code: string;
  data?: T;
  dataArray?: T[];

  success(): boolean {
    if (TextUtils.equals("200", this.code)) {
      if (this.data != null) {
        return TextUtils.equals("0000", this.getJsonData().resultCode);
      }
    }
    return false;
  }

  getCode(): string {
    if (!TextUtils.equals("200", this.code)) {
      return this.code;
    }
    if (this.data != null) {
      return this.getJsonData().resultCode;
    }
    return this.code;
  }

  getMsg(): string {
    if (!TextUtils.equals("200", this.code)) {
      return this.msg;
    }
    if (this.data != null) {
      return this.getJsonData().resultMsg;
    }
    return this.msg;
  }

  getJsonData(): any {
    return JSON.parse(JSON.stringify(this.data))
  }
}



